<?
	require_once('functions.php');

	drizzo_db_connect();
	
	$page_converted_count = 0;

	$page_conversion = @mysql_query("SELECT `ID`,`page_parent` FROM `$drizzo_posts`");
	if(!mysql_errno()) {
		while($row = @mysql_fetch_assoc($page_conversion)) {
			$id = "";
			$old_parent = "";

			$id = $row['ID'];
			$old_parent = $row['page_parent'];
			
			if($old_parent > 0) {
				$id_conversion = @mysql_query("SELECT `ID` FROM `$drizzo_posts` WHERE `import_id`='$old_parent'");
				while($row = @mysql_fetch_assoc($id_conversion)) {
					$new_parent = "";

					$new_parent = $row['ID'];
				}
				@mysql_query("UPDATE `$drizzo_posts` SET `page_parent`='$new_parent' WHERE `ID`='$id'") or die("I quit life.");

				$page_converted_count++;
			}
		}

		echo "<p>" . $page_converted_count . " Pages have had their parent Pages retrieved and converted.</p>";

	} else {
		echo "Couldn't find any pages to convert.";
	}
?>
